<?php
/**
 * Zend Component 
 **/
class ZendComponent extends Component {
    
    public $components = array();
    
    public function import($key) {
            $this->__setIncludePath();
            App::import('Vendor', "Zend.$key", array(
                    'file' => 'Zend' . DS . str_replace(DS, '/', $key) . '.php',
            ));
            //require dirname(dirname(dirname(__FILE__))) . DS . 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', $key) . '.php';
    }
    public function include_barcode(){
        include dirname(dirname(dirname(__FILE__))) . DS . 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', "Barcode") . DS.'Object'.DS.'Ean13.php';
    }
    public function import_barcode(){
        $this->__setIncludePath();
        require dirname(dirname(dirname(__FILE__))) . DS . 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', "Barcode") . '.php';
        require dirname(dirname(dirname(__FILE__))) . DS . 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', "Barcode") . DS.'Object'.DS.'Ean13.php';
    }
    private function __setIncludePath() {
        $separator = PATH_SEPARATOR; 
        $includePath = explode($separator, ini_get("include_path"));
        $includePath[] = dirname(dirname(dirname(__FILE__))) . DS . 'Vendor' . DS;
        ini_set("include_path", implode($separator, $includePath));
    }
    
    public function writeQrcode($title,$code,$mode="F") {
        $this->__setIncludePath();
        require APP. 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', "Barcode") . '.php';
        $options=array(
            'text' => $code,
            'font' => 4
        );
        //$barcode = new Zend_Barcode_Object_Ean13($options);
        $source = Zend_Barcode::factory("EAN13", "image",$options)->draw();
        if($mode == "F"){
            imagepng($source,$title);
        }else{
            imagepng($source);
        }
    }
    public function writeGiftCode($title,$code,$mode="F"){
        $this->__setIncludePath();
        require APP. 'Vendor' . DS.'Zend' . DS . str_replace(DS, '/', "Barcode") . '.php';
        $options=array(
            'text' => $code,
            'font' => 4
        );
        //$barcode = new Zend_Barcode_Object_Ean13($options);
        $source = Zend_Barcode::factory("CODE128", "image",$options)->draw();
        if($mode == "F"){
            imagepng($source,$title);
        }else{
            imagepng($source);
        }
    }
}
